package com.lcl.stock.controller;

import com.lcl.stock.pojo.domain.*;
import com.lcl.stock.service.StockService;
import com.lcl.stock.vo.resp.PageResult;
import com.lcl.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @ClassName StockController
 * @Description TODO:定义股票相关接口控制器
 * @Author 28901
 * @Date 2025/2/24 21:36
 * @Version 1.0
 */
@Api(value = "api/quot", tags = {"TODO:定义股票相关接口控制器"})
@RestController
@RequestMapping("api/quot")
public class StockController {
    @Autowired
    private StockService stockService;

    /**
     * 获取国内大盘最新数据
     * @return
     */
    @ApiOperation(value = "获取国内大盘最新数据", notes = "获取国内大盘最新数据", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerMarketInfo(){
        return stockService.getInnerMarketInfo();
    }

    /**
     *需求说明: 获取沪深两市板块最新数据，以交易总金额降序查询，取前10条数据
     * @return
     */
    @ApiOperation(value = "获取沪深两市板块最新数据", notes = "获取沪深两市板块最新数据", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> sectorAll(){
        return stockService.sectorAllLimit();
    }

    /**
     * 分页查询最新的股票交易数据
     * @param page 当前页
     * @param pageSize 每页大小
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页大小")
    })
    @ApiOperation(value = "分页查询最新的股票交易数据", notes = "分页查询最新的股票交易数据", httpMethod = "GET") // 数据类型不能错：int ！= Integer
    @GetMapping("/stock/all")
    public R<PageResult<StockUpdownDomain>> getStockInfoByPage(@RequestParam(value = "page", required = false,defaultValue = "1") Integer page,
                                                               @RequestParam(value = "pageSize", required = false,defaultValue = "20") Integer pageSize){
        return stockService.getStockInfoByPage(page,pageSize);
    }

    /**
     * 统计沪深两市个股最新交易数据，并按涨幅降序排序查询前4条数据
     * @return
     */
    @ApiOperation(value = "统计沪深两市个股最新交易涨幅降序的前4条数据", notes = "统计沪深两市个股最新交易涨幅降序的前4条数据", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> getStockInfoIncrease(){
        return stockService.getStockInfoIncrease();
    }




    /**
     * 统计最新股票交易日内每分钟的涨跌停的股票数量
     * @return
     */
    @ApiOperation(value = "统计最新股票交易日内每分钟的涨跌停的股票数量", notes = "统计最新股票交易日内每分钟的涨跌停的股票数量", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public R<Map<String, List>> getStockUpDownCount(){
      return stockService.getStockUpDownCount();
    }

    /**
     * 将指定页的股票数据导出到excel表下
     * @param response 响应
     * @param page  当前页
     * @param pageSize 每页大小
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页"),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页大小")
    })
    @ApiOperation(value = "将指定页的股票数据导出到excel表下")
    @GetMapping("/stock/export")
    public void stockExport( HttpServletResponse response,
                             @RequestParam(value = "page",required = false,defaultValue = "1")Integer page,
                             @RequestParam(value = "pageSize",required = false,defaultValue = "20")Integer pageSize){
        stockService.stockExport(response,page,pageSize);
    }

    /**
     * 统计大盘t日和t-1日每分钟交易量的统计
     * @return
     */
    @ApiOperation(value = "统计大盘t日和t-1日每分钟交易量的统计",notes = "统计大盘t日和t-1日每分钟交易量的统计",httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String,List>> getComparedStockTradeAmt(){
        return stockService.getComparedStockTradeAmt();
    }

    /**
     * 统计最新交易时间点下股票（A股）在各个涨幅区间的数量
     * @return
     */
    @ApiOperation(value = "统计最新股票（A股）在各个涨幅区间的数量",notes = "统计最新交易时间点下股票（A股）在各个涨幅区间的数量",httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<Map<String,Object>> getIncreaseRangeInfo(){
        return stockService.getIncreaseRangeInfo();
    }

    /**
     * 获取指定股票T日的分时数据
     * @param stockCode 股票编码
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "stockCode", value = "股票编码")})
    @ApiOperation(value = "获取指定股票T日的分时数据",notes = "获取指定股票T日的分时数据",httpMethod = "GET")
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getStockScreenTimeSharing(@RequestParam(value = "code",required = true) String stockCode){
        return stockService.getStockScreenTimeSharing(stockCode);
    }

    /**
     * 统计指定股票的日K线数据
     * @param stockCode 股票编码
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "stockCode", value = "股票编码")})
    @ApiOperation(value = "统计指定股票的日K线数据",notes = "统计指定股票的日K线数据",httpMethod = "GET")
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStockScreenDkLine(@RequestParam(value = "code",required = true) String stockCode){
        return stockService.getStockScreenDkLine(stockCode);
    }





}